package net.sharpf2.api.interfaces;

import net.sharpf2.sfcore.input.Keyboard;
import net.sharpf2.api.Globals;
import net.sharpf2.api.Script;
import net.sharpf2.api.game.Interfaces;
import net.sharpf2.api.util.Mathematics;

/**
 * Handling Skills
 * @author Sam Smekens
 */
public class Statistics {
    private static Keyboard keyboard = Globals.CONTROLLER.getKeyboard();
   
    /**
     * Hovers a skill 'tab'
     * @param skill ID of skill. Please use Constants from this class
     */
    public static void hover(int skill){
        Tabs.checkAndOpen(Tabs.Constants.TAB_STATS);
        Interfaces.get(Constants.STATISTICS_TAB, skill).getActions().hover();
    }
    
    /**
     * Set a level target for a certain skill
     * @param skill         ID of skill. Use Constants class to indicate which skill to target at.
     * @param targetLevel   Target level, Maximum 99, or 120 for dungeoneering.
     */
    public static void setLevelTarget(int skill, int targetLevel){
        if((targetLevel <= 99 && Constants.SKILL_BOX[skill] != Constants.DUNGEONEERING) || (targetLevel <= 120 && Constants.SKILL_BOX[skill] == Constants.DUNGEONEERING)){
            Tabs.checkAndOpen(Tabs.Constants.TAB_STATS);
            Interfaces.get(Constants.STATISTICS_TAB, skill).getActions().click("(Set Level Target|Stufen-Ziel einstellen|Fixer objectif de niveau)");
            while(Interfaces.getInterfaceByText("(Set Level Target|Welche Stufe*|Quel niveau*)") == null && !Thread.currentThread().isInterrupted()){
                Script.sleep(50);
            }
            Script.sleep(Mathematics.random(500, 750));
            keyboard.sendKeys(Integer.toString(targetLevel), true);
        }
    }
    
    /**
     * Set a level target for a certain skill
     * @param skill     ID of skill. Use Constants class to indicate which skill to target at.
     * @param targetXP  Target XP, Maximum 200.000.000
     */
    public static void setXPTarget(int skill, int targetXP){
        if(targetXP <= 200000000){
            Tabs.checkAndOpen(Tabs.Constants.TAB_STATS);
            Interfaces.get(Constants.STATISTICS_TAB, skill).getActions().click("(Set XP Target|EP-Ziel einstellen|Fixer objectif d'XP)");
            while(Interfaces.getInterfaceByText("(Set XP Target|Welches EP-Ziel*|Quel objectif d'XP*)") == null && !Thread.currentThread().isInterrupted()){
                Script.sleep(50);
            }
            Script.sleep(Mathematics.random(500, 750));
            keyboard.sendKeys(Integer.toString(targetXP), true);
        }
    }
    
    public static class Constants {
        public final static int STATISTICS_TAB = 320;
        public final static int TARGET_LEVEL_INTERFACE = 752;
        public final static int ATTACK = 1;
        public final static int STRENGTH = 4;
        public final static int DEFENCE = 21;
        public final static int RANGED = 45;
        public final static int PRAYER = 69;
        public final static int MAGIC = 87;
        public final static int RUNECRAFTING = 103;
        public final static int CONSTRUCTION = 127;
        public final static int DUNGEONEERING = 151;
        public final static int CONSTITUTION = 2;
        public final static int AGILITY = 12;
        public final static int HERBLORE = 29;
        public final static int THIEVING = 53;
        public final static int CRAFTING = 77;
        public final static int FLETCHING = 94;
        public final static int SLAYER = 111;
        public final static int HUNTER = 135;
        public final static int MINING = 3;
        public final static int SMITHING = 20;
        public final static int FISHING = 37;
        public final static int COOKING = 61;
        public final static int FIREMAKING = 85;
        public final static int WOODCUTTING = 102;
        public final static int FARMING = 119;
        public final static int SUMMONING = 143;
        public final static int SKILL_BOX[] = {ATTACK, DEFENCE, STRENGTH, CONSTITUTION, RANGED, PRAYER, MAGIC, COOKING, WOODCUTTING, FLETCHING, FISHING, FIREMAKING, CRAFTING, SMITHING, MINING, HERBLORE, AGILITY, THIEVING, SLAYER, FARMING, RUNECRAFTING, HUNTER, CONSTRUCTION, SUMMONING, DUNGEONEERING};
    }
}